import React, { memo } from 'react';
import { Table } from 'antd';
import './style.less';
import AddModal from './cPages/add-modal';
/* 表格组件 */
export default memo(function Mytable(props) {
  /* 获取数据组成列表格，赋值给table的colums属性 */
  let templateColums = [];
  if (props.dataList.list) {
    let columObj = props.dataList.list[0];
    let i = 0;
    for (let item in columObj) {
      let templateCol = {};
      templateCol.title = item;
      templateCol.dataIndex = item;
      templateCol.key = i;
      templateCol.ellipsis = true;
      templateCol.align = 'center';
      templateColums.push(templateCol);
      i++;
    }
  }
  const data = props.dataList.list;
  return (
    <div className="my-table">
      <div className="controls">
        <AddModal />
      </div>
      <Table
        size="middle"
        className="components-table-demo-nested"
        columns={templateColums}
        dataSource={data}
        rowSelection={true}
        tableLayout="fixed"
      />
    </div>
  );
});
